﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.11f1
 *Date:           2019-04-07
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using System;

namespace IFramework
{
    public interface Loader
    {
        void Load();

        void Unload();
    }

    public class AssetLoader : Loader
    {
        #region Loader implementation

        public void Load()
        {
            asset = ABAssets.Instance.Load(assetPath, assetType);
            if (onLoad != null)
            {
                onLoad(this);
            }
        }

        public void Unload()
        {
            asset.UnLoad();
            if (onUnload != null)
            {
                onUnload(this);
            }
        }

        #endregion

        public string assetPath;
        public Type assetType;
        public ABAsset asset;

        public Action<AssetLoader> onLoad;
        public Action<AssetLoader> onUnload;
    }

    public class BundleLoader : Loader
    {
        public string bundleName;
        public ABBundle bundle;

        #region Loader implementation

        public void Load()
        {
            bundle = ABBundles.LoadSync(bundleName);
        }

        public void Unload()
        {
            bundle.UnLoad();
        }

        #endregion
    }
}
